<?php

class image_m extends Model {

    var $errors = '';

    function image_m () {
        parent::Model();
    }

    function create() {
        $config = array();
        $config['upload_path'] = './assets/upload/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']	= '800';
        $config['max_width'] = '2048';
        $config['max_height'] = '1536';
        $config['file_name'] = $this->input->post('id');
        $config['overwrite'] = TRUE;

        $this->upload->initialize($config);

        if($this->upload->do_upload('filename')) {
            // if uploaded do resize
            $data = $this->upload->data();
            $iconfig['image_library'] = 'gd2';
            $iconfig['source_image']	= $data['full_path'];
            $iconfig['create_thumb'] = FALSE;
            $iconfig['maintain_ratio'] = FALSE;
            $iconfig['width']	 = 174;
            $iconfig['height']	= 125;

            $this->image_lib->initialize($iconfig);
            $this->image_lib->resize();

            return array('success'=>'success','data'=>$data,'message'=>'Dodavanje slike je uspjesno zavrseno!');
        }else {
            return array('success'=>'failed','message'=>$this->upload->display_errors(' ','<br />'));
        }

    }

}
?>